package com.zhanglu.fun.services.datacenter.forumthread;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.zhanglu.fun.services.datacenter.common.ResultResponse;
import com.zhanglu.fun.services.datacenter.entity.ForumThread;

import java.util.List;

/**
 * @author jing
 * @description 主题业务
 * @date 2017/6/26 0026 23:11
 */
@Service
public class ForumThreadService {
    @Autowired
    private ForumThreadMapper forumThreadMapper;

    public ResultResponse getForumThreads(ForumThread forumThread) {
        if (forumThread.getPage() != null && forumThread.getRows() != null) {
            PageHelper.startPage(forumThread.getPage(), forumThread.getRows());
        }
        return new ResultResponse<>(true, forumThreadMapper.selectForumThread(forumThread));
    }

    public ResultResponse deleteForumThread(Long id) {
        return new ResultResponse<>(forumThreadMapper.deleteByPrimaryKey(new ForumThread().setId(id)) > 0, null);
    }

    public ResultResponse addForumThread(ForumThread forumThread) {
        return new ResultResponse<>(forumThreadMapper.insert(forumThread) > 0, null);
    }

    public ResultResponse updateForumThread(ForumThread forumThread) {
        return new ResultResponse<>(forumThreadMapper.updateByPrimaryKeySelective(forumThread) > 0, null);
    }

}
